//
//  HMTabBarViewController.swift
//  微博
//
//  Created by 程双岐 on 16/9/19.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit
import SVProgressHUD

class HMTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = HMTabBar()

        tabbar.hmDelegate = self
        
        tabbar.block = {[weak self] in
            if !HMUserAccpuntViewModel.sharedUserAccountViewModel.isLogin {
                SVProgressHUD.showError(withStatus: "您没登录")
            }
         
            //最上层的window
            
            if let target = self{
                let componseView = HMComposeView()
                componseView.show(target: target)
            }
            
            
            
        }
        setValue(tabbar, forKey: "tabBar")
        
        
        UITabBar.appearance().tintColor = UIColor.orange
        
        addChildViewController(childController: HMHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: HMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: HMDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: HMProfileTableViewController(), title: "我的", imageName: "tabbar_profile")

    }

    func addChildViewController( childController: UIViewController,title :String,imageName:String) {
        childController.title = title
        childController.tabBarItem.image = UIImage(named:imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 14)], for:.normal)
        
        let nav = HMNavigationViewController(rootViewController: childController)
        addChildViewController(nav)
        
        
    }

    
}

extension HMTabBarViewController:HomeDelegate
{
    func tabBarButtonAction() {
        print("哈哈")
    }
}

